//
//  CJFilmCriticTableViewCell.m
//  KaiJing
//
//  Created by lanou on 16/1/13.
//  Copyright © 2016年 HuangZuCui. All rights reserved.
//

#import "CJFilmCriticTableViewCell.h"
#import "UIImageView+WebCache.h"
@implementation CJFilmCriticTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
     
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenWidth / 2)];
        [self.contentView addSubview:_imageV];
        
        //标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _imageV.bottom + 10, kScreenWidth - 20, 40)];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = -1;
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:_titleLabel];
        
        
        //内容
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 70)];
        _contentLabel.textAlignment = NSTextAlignmentCenter;
        _contentLabel.numberOfLines = -1;
        _contentLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_contentLabel];
        
        
        //下面视图集合
        _bottomView = [[CJCellBottomView alloc] initWithFrame:CGRectMake(0, _contentLabel.bottom + 5, kScreenWidth, 25)];
        [self.contentView addSubview:_bottomView];
        
        //点赞
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_norml"] forState:(UIControlStateNormal)];
        [_bottomView.praiseButton setImage:[UIImage imageNamed:@"parise_select"] forState:(UIControlStateSelected)];
        _bottomView.praiseLabel.text = @"赞";
        //评论
        [_bottomView.commentButton setImage:[UIImage imageNamed:@"comment"] forState:(UIControlStateNormal)];
        _bottomView.commentLabel.text = @"评论";
        
        //更多
        [_bottomView.moreButton setImage:[UIImage imageNamed:@"more"] forState:(UIControlStateNormal)];
        
    }
    return self;
}




- (void)setModel:(CJFilmCriticModel *)model
{
    _model = model;
    
     NSString *urlStr = [NSString stringWithFormat:@"http://morguo.com/%@",_model.image];

    CGFloat height = [CJFilmCriticTableViewCell imageVHeightForModel:_model];
    _imageV.frame = CGRectMake(5, 0, kScreenWidth, height);
    [_imageV sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"recommend_selected"]];
    
    _titleLabel.frame = CGRectMake(10, _imageV.bottom + 10, kScreenWidth - 20, 40);
    _titleLabel.text = _model.subject;
    
    _contentLabel.frame = CGRectMake(10, _titleLabel.bottom + 10, kScreenWidth - 20, 70);
    _contentLabel.text = _model.intro;
    
    _bottomView.frame = CGRectMake(0, _contentLabel.bottom + 5, kScreenWidth, 25);
    
}


+(CGFloat)imageVHeightForModel:(CJFilmCriticModel *)model
{
    CGFloat width = (CGFloat)[model.width floatValue];
    CGFloat height = (CGFloat)[model.height floatValue];

    return height / width * kScreenWidth;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
